package com.xdtech.${moduleName}.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
import java.sql.Timestamp;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.xdtech.core.model.BaseModel;

/**
 * 
 * @author max.zheng
 * @create ${createTime}
 * @since 1.0
 * @see 
 */
@Entity
@Table(name="${tableName}")
public class ${modelName?cap_first} extends BaseModel implements Serializable{
	private static final long serialVersionUID = 1L;
<#list fields as field>
	<#if field.name='id'>
	@Id
	@Column(name = "${field.tableFieldName}")
	@GeneratedValue(strategy = GenerationType.AUTO)
	<#else>
	@Column(name="${field.tableFieldName}")
	</#if>
	private ${field.type} ${field.name};
</#list>

<#list modelMapps as mapp>
	<#if mapp.mappedType='OneToMany'>
	//一对多
	@OneToMany(fetch=FetchType.LAZY,mappedBy="${modelName}")
	List<${(mapp.mappedByModel)?cap_first}> ${(mapp.mappedByModel)}s = new ArrayList<${(mapp.mappedByModel)?cap_first}>();
	<#elseif mapp.mappedType='ManyToOne'>
	//多对一
	@ManyToOne
    @JoinColumn(name = "${mapp.mappedBy}_ID")
    ${(mapp.mappedByModel)?cap_first} ${(mapp.mappedByModel)};
    <#elseif mapp.mappedType='OneToOne'>
    //一对一
	@OneToOne
    @JoinColumn(name = "${mapp.mappedBy}_ID",insertable=true,unique=true)
    ${(mapp.mappedByModel)?cap_first} ${(mapp.mappedByModel)};
    <#elseif mapp.mappedType='ManyToMany'>
    //多对多
	@ManyToMany
	@JoinTable(
			name = "${tableName}_${mapp.mappedBy}",
			joinColumns={@JoinColumn(
                    name="${tableName}_ID",
                    referencedColumnName="ID"
                    )},
            inverseJoinColumns={@JoinColumn(
                            name="${mapp.mappedBy}_ID",
                            referencedColumnName = "ID")}
			)
    List<${(mapp.mappedByModel)?cap_first}> ${(mapp.mappedByModel)}s = new ArrayList<${(mapp.mappedByModel)?cap_first}>();
	</#if>
</#list>

<#list fields as field>
	public void set${field.name?cap_first}(${field.type} ${field.name}) {
		this.${field.name} = ${field.name};
	}
	public ${field.type} get${field.name?cap_first}() {
		return ${field.name};
	}
</#list>

<#list modelMapps as mapp>
	<#if mapp.mappedType='OneToMany'>
	public List<${(mapp.mappedByModel)?cap_first}> get${(mapp.mappedByModel)?cap_first}s()
	{
		return ${(mapp.mappedByModel)?cap_first}s;
	}

	public void set${(mapp.mappedByModel)?cap_first}s(List<${(mapp.mappedByModel)?cap_first}> ${(mapp.mappedByModel)?cap_first}s)
	{
		this.${mapp.mappedByModel}s = ${mapp.mappedByModel}s;
	}
	<#elseif mapp.mappedType='ManyToOne'>
	public ${(mapp.mappedByModel)?cap_first} get${(mapp.mappedByModel)?cap_first}()
	{
		return ${mapp.mappedByModel};
	}
	public void set${(mapp.mappedByModel)?cap_first}(${(mapp.mappedByModel)?cap_first} ${mapp.mappedByModel})
	{
		this.${mapp.mappedByModel} = ${mapp.mappedByModel};
	}
    <#elseif mapp.mappedType='OneToOne'>
    public ${(mapp.mappedByModel)?cap_first} get${(mapp.mappedByModel)?cap_first}()
	{
		return ${mapp.mappedByModel};
	}
	public void set${(mapp.mappedByModel)?cap_first}(${(mapp.mappedByModel)?cap_first} ${mapp.mappedByModel})
	{
		this.${mapp.mappedByModel} = ${mapp.mappedByModel};
	}
    <#elseif mapp.mappedType='ManyToMany'>
	public List<${(mapp.mappedByModel)?cap_first}> get${(mapp.mappedByModel)?cap_first}s()
	{
		return ${(mapp.mappedByModel)}s;
	}

	public void set${(mapp.mappedByModel)?cap_first}s(List<${(mapp.mappedByModel)?cap_first}> ${(mapp.mappedByModel)?cap_first}s)
	{
		this.${mapp.mappedByModel}s = ${mapp.mappedByModel}s;
	}
	</#if>
</#list>
}
